package com.example.gzysmartcity.ui.adapter;

import android.graphics.Color;
import android.widget.ImageView;

import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.gzysmartcity.R;
import com.example.gzysmartcity.repository.model.PersonExpend;

import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class CustomRvAdapter extends BaseQuickAdapter<PersonExpend, BaseViewHolder> {
    public CustomRvAdapter(int layoutResId) {
        super(layoutResId);
        mSimpleDateFormat=new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA);
    }
    private final SimpleDateFormat mSimpleDateFormat;
    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, PersonExpend personExpend) {
        baseViewHolder.setText(R.id.rv_custom_name,personExpend.getName());
        baseViewHolder.setText(R.id.rv_custom_time,"最近来访："+mSimpleDateFormat.format(new Date((long)Integer.parseInt(personExpend.getTime())*1000)));
        ImageView imageView=baseViewHolder.getView(R.id.image_rv_custom);
        if (Integer.parseInt(personExpend.getMoney())==0){
            baseViewHolder.setText(R.id.rv_sell_money,"消费总额：无");
        }else {
            baseViewHolder.setText(R.id.rv_sell_money,"消费总额："+personExpend.getMoney());
        }

        Glide.with(getContext()).load(personExpend.getPic()).error(R.drawable.error).into(imageView);
        baseViewHolder.setText(R.id.tv_custom_time, mSimpleDateFormat.format(new Date((long)TimeUtils.getNowMills())));
        if(Integer.parseInt(personExpend.getMoney())>10){
            baseViewHolder.setBackgroundColor(R.id.line_custom,Color.parseColor("#BBFFBB"));
        }else {
            baseViewHolder.setBackgroundColor(R.id.line_custom,Color.parseColor("#ffffff"));
        }
    }
}
